import React from "react";
import "../css/Borard.css"
import eventEmitter from '../event';

class Borard extends React.Component{
  constructor(props){
    super(props)
    this.state = {
      messages:[]
    }
  }

  render(){
    return(
      <div className="borard_container">
        {
          this.state.messages.map((element,index)=>{
            return <div className="message" key={index}>
              <h3>{element.content}</h3>
              <h3>{element.date}</h3>
            </div>
          })
        }
      </div>
    );
  }

  //mounted
  componentDidMount(){
    eventEmitter.addListener("sendMessageTooBoard",(message)=>{
      console.log(message);
      this.state.messages.push(message);
      this.setState({
        message:this.state.messages
      })
    })
  }
}

export default Borard;